// 计划
import request from '@/utils/request'
import { toolSync } from '../sync'

// 计划列表
export function getAdList (data) {
  const params = {
    filtering: [],
    task_id: parseInt(data.task_id),
    order_by: data.order_by,
    order_type: data.order_type,
    page: data.page,
    page_size: data.page_size
  }
  if (data.status) {
    if( data.status === 'AD_STATUS_NOT_DELETE' ){
      params.filtering.push({
        field: 'status',
        operator: 'NOT_EQUALS',
        value: 'AD_STATUS_DELETE'
      })
    }else {
      params.filtering.push({
        field: 'status',
        operator: 'EQUALS',
        value: data.status
      })
    }
  }
  if (data.account_id) {
    params.filtering.push({
      field: 'account_id',
      operator: 'EQUALS',
      value: data.account_id
    })
  }
  if (data.ad_create_time && data.ad_create_time.length > 0) {
    params.filtering.push({
      field: 'ad_create_time',
      operator: 'GREATER_EQUALS',
      value: `${data.ad_create_time[0]} 00:00:00`
    })
    params.filtering.push({
      field: 'ad_create_time',
      operator: 'LESS_EQUALS',
      value: `${data.ad_create_time[1]} 23:59:59`
    })
  }
  return request({
    url: process.env.VUE_APP_ADV_OCEAN_API +  '/admin/ocean/ad/select',
    method:'post',
    data: params
  })
}

// 计划详情
export function getAdDetails (id) {
  return request({
    url: process.env.VUE_APP_ADV_OCEAN_API + '/admin/ocean/ad/read',
    method:'post',
    data: { id:id }
  })
}


// 计划同步
export function adSync (account_ids,type) {
  return toolSync(account_ids,'AD')
}
